approveAppointmentRating
approveAppointmentRating
This method handles the approval or rejection of an appointment rating, ensuring only authorized agents can perform the action, and updates related rating statistics accordingly.
-
Initialize Transaction
- Use an existing
QueryRunnerif provided, or create a new one. - Start a database transaction.
- Use an existing
-
Validate Approving Agent
- Retrieve the agent with the given
agent_id. - Confirm the agent exists and has the appropriate role (
AgentSuperAdminorAgentAdmin). - If the agent is not found or unauthorized, throw a NotFoundException.
- Retrieve the agent with the given
-
Retrieve Appointment Rating
- Find the rating record on
rating_appointmenttable bybooking_id. - Load related entities: agent, business location, and who approved it.
- If no rating is found, throw a NotFoundException.
- Find the rating record on
-
Check Rating Status
- Ensure the rating’s current status is
'pending'. - Confirm the rating has not already been approved (
approvedByisnull). - If the rating is not pending or already approved/rejected, throw a ConflictException.
- Ensure the rating’s current status is
-
Approve or Reject Rating
-
Based on the
statusin the input DTO:- If
'approve', call the rating’sapprovemethod, passing the approving agent. - If
'reject', call the rating’srejectmethod, passing the approving agent.
- If
-
-
Save Rating Update
- Persist the updated rating record within the transaction.
-
Update Related Ratings (On Approval Only)
-
If approved, update related ratings statistics:
- Provider rating statistics
- Staff rating statistics
- Clinic rating statistics
-
Use a shared
updateRatinghelper function with relevant repositories.
-
-
Commit or Rollback Transaction
- Commit the transaction if all steps succeed.
- Rollback the transaction if any error occurs during processing.
-
Release Query Runner
- Release database resources held by the
QueryRunner.
- Release database resources held by the
-
Return Result
- Return a success response indicating whether the rating was approved or rejected.